home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / dos / mkMOVERSdbldirs.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  4KB  |  160 lines

  1. /*
  2. * =====================================================================
  3. *
  4. *   Program : MKDBLDIRS or MakeDoubleDirectories.
  5. *
  6. *   Changed : For The Movers  12-10-87 
  7. *
  8. *   Author : J. Van Houtven.                     Date : Sept 12th 1987.
  9. *
  10. * =====================================================================
  11. */
  12.  
  13.  
  14. #include "libraries/dosextens.h"
  15.  
  16. # define MAX_NR_OF_DOUBLESUBDIRS  100
  17.  
  18. /* Only UnLock() locks that are obtained with Lock() or DupLock() (?) !!!! */
  19.  
  20. extern struct FileLock *CreateDir(), *CurrentDir();
  21.  
  22. struct FileLock *next_lock[MAX_NR_OF_DOUBLESUBDIRS*2+1],
  23.                 *current_lock = 0L,
  24.                 *first_lock;
  25.  
  26. int  i, nr_of_doublesubdirs;
  27.  
  28.  
  29. main(argc,argv)
  30. int argc;
  31. char *argv[];
  32. {
  33.  char  *dirname, *dirname2, *drivename;
  34.  struct FileLock *create_lock;
  35. void die(), CloseALL();
  36.  
  37.  if(argc>1)
  38.   drivename = argv[1];
  39.  else
  40.  {
  41.   puts("MKDBLDIRS v2.0 : (c) 1987 by AMY PRODUCTIONS.\nSpecially developed for [EMD]. Adapted for THE MOVERS (Oct. 1987).\n ");
  42.   puts("Usage : MKDBLDIRS <drive> <nr_of_doublesubdirs> <subdir1_name> <subdir2_name>\n");
  43.   puts("<drive>               : 'df1:', 'df2:' or 'df3:'");
  44.   puts("<nr_of_doublesubdirs> : INTEGER NUMBER between [1-100], DEFAULT = 10");
  45.   puts("<subdir1_name>        : CHAR STRING, DEFAULT = \" THE MOVERS in 1949 !!! \"");
  46.   puts("<subdir2_name>        : CHAR STRING, DEFAULT = \" * DRAGO & AMADEUS * \"\n");
  47.   puts("Note : All subdirs will be automagically protected !\n");
  48.   exit(0);
  49.  } 
  50.  
  51.  if(argc>2)
  52.   {
  53.    nr_of_doublesubdirs = atoi(argv[2]);
  54.    if((nr_of_doublesubdirs <1) || (nr_of_doublesubdirs>MAX_NR_OF_DOUBLESUBDIRS))
  55.    {
  56.     puts("<nr_of_doublesubdirs> must be within [1-100] !\n");
  57.     exit(0);
  58.    }
  59.   }
  60.  else
  61.   nr_of_doublesubdirs = 10;
  62.  
  63.  if(argc>3)
  64.   dirname = argv[3];
  65.  else
  66.   dirname = " THE MOVERS in 1949 !!! ";
  67.  
  68.  if(argc>4)
  69.   dirname2 = argv[4];
  70.  else
  71.   dirname2 = " * DRAGO & AMADEUS * ";
  72.  
  73.  /* ====== mkdirs routine ======  */
  74.  
  75.  /* init next_lock[] */
  76.  for(i=0;i<=nr_of_doublesubdirs*2;i++) next_lock[i] = 0;
  77.  
  78.  first_lock = CurrentDir(0);
  79.  CurrentDir(first_lock);
  80.  
  81.  /* lock drive df? */
  82.  if( (current_lock = Lock(drivename,ACCESS_WRITE) ) == 0)
  83.  {
  84.   die("Couldn't get a lock on specified drive !\n");
  85.  }
  86.  
  87.  /* next_lock (nl. next_lock[0]) word gelijkgesteld aan de lock op df1: */
  88.  next_lock[0] = current_lock; /* let op next_lock[0] is een copy v.e. pointer
  89.                                  en moet niet ge_unlocked worden */ 
  90.  
  91.  for(i=0;i<nr_of_doublesubdirs*2;i+=2)
  92.  {
  93.   CurrentDir(next_lock[i]);
  94.  
  95.   /* Test if "dirname" already exists ... */
  96.   /* BUG : We test this by trying to obtain a lock on "dirname"
  97.      but "dirname" could still be a normal file ! */
  98.   if((create_lock = Lock(dirname,ACCESS_WRITE)) !=0)
  99.   {
  100.    UnLock(create_lock);
  101.    die("Subdirectory already exists !\n");
  102.   }
  103.  
  104.   if((create_lock = CreateDir(dirname)) == 0)
  105.    die("Couldn't create subdirectory !\n");
  106.   UnLock(create_lock);
  107.  
  108.   SetProtection(dirname,1);
  109.  
  110.   if((next_lock[i+1] = Lock(dirname,ACCESS_WRITE)) == 0)
  111.    die("Couldn't obtain a lock on subdirectory\n");
  112.  
  113.  
  114.   CurrentDir(next_lock[i+1]);
  115.  
  116.   /* Test if "dirname2" already exists ... */
  117.   /* BUG : We test this by trying to obtain a lock on "dirname2"
  118.      but "dirname2" could still be a normal file ! */
  119.   if((create_lock = Lock(dirname2,ACCESS_WRITE)) !=0)
  120.   {
  121.    UnLock(create_lock);
  122.    die("Subdirectory already exists !\n");
  123.   }
  124.  
  125.   if((create_lock = CreateDir(dirname2)) == 0)
  126.    die("Couldn't create subdirectory !\n");
  127.   UnLock(create_lock);
  128.  
  129.   SetProtection(dirname2,1);
  130.  
  131.   if((next_lock[i+2] = Lock(dirname2,ACCESS_WRITE)) == 0)
  132.    die("Couldn't obtain a lock on subdirectory\n");
  133.    
  134.  
  135.  }
  136.  
  137.  CloseALL();
  138.  
  139. } /* ====== end main ====== */
  140.  
  141. void CloseALL()
  142. {
  143.  
  144.  for(i=nr_of_doublesubdirs*2;i>=1;i--) if(next_lock[i]) UnLock(next_lock[i]);
  145.  
  146.  CurrentDir(first_lock);
  147.  
  148.  /* Lock op drive df? */
  149.  if(current_lock) UnLock(current_lock);
  150.  
  151.  
  152. void die(errormsg)
  153. char *errormsg;
  154. {
  155.  puts(errormsg);
  156.  CloseALL();
  157.  exit(0);
  158. }
  159.